package com.woniuxy.microsystemuapserver.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.microsystemuapserver.bean.PageResult;
import com.woniuxy.microsystemuapserver.bean.UserBean;
import com.woniuxy.microsystemuapserver.mapper.UserMapper;
import com.woniuxy.microsystemuapserver.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: huhenggg
 * @Date: 2021/1/25 0025 下午 7:48
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 分页查询
     * @param page
     * @param size
     * @param userBean
     * @return
     */
    @Override
    public PageResult<List<UserBean>> findByPage(int page, int size,UserBean userBean) {
        PageResult<List<UserBean>> result = new PageResult<>();
        Page<UserBean> starPage = PageHelper.startPage(page, size);
        List<UserBean> userBeans = userMapper.findAll(userBean);

        result.setCurrentPage(page);
        result.setSize(size);
        result.setTotal(starPage.getTotal());
        result.setTotalPage(starPage.getPages());
        result.setData(userBeans);
        return result;
    }

    /**
     * 修改用户信息
     * @param userBean
     * @return
     */
    @Override
    public int updateUserBean(UserBean userBean) {
        return userMapper.updateUserBean(userBean);
    }

    /**
     * 添加用户
     * @param userBean
     * @return
     */
    @Override
    public int addUser(UserBean userBean) {
        return userMapper.addUser(userBean);
    }

    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @Override
    public Map findAUser(Long userId) {
        return userMapper.findAUser(userId);
    }

    @Override
    public int addBossUser(UserBean userBean) {
        return userMapper.addBossUser(userBean);
    }

    @Override
    public UserBean findRoleAndPermission(String userAccount) {
        return userMapper.findRoleAndPermission(userAccount);
    }

    @Override
    public UserBean login(String loginName) {
        return userMapper.login(loginName);
    }


}
